package com.jiang.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jiang.filter
 * @Description:
 * @Date 2022/5/23 10:48
 */
//@WebFilter("/*")
public class permFilter  implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //强传
        HttpServletRequest request =(HttpServletRequest)servletRequest;
        HttpServletResponse response=(HttpServletResponse)servletResponse;
        //获取ulr的地址
        String uri = request.getRequestURI();
        System.out.println("=====uri===="+uri);
        //判断获得路径 放行所有静态资源  放行用户路径 首页 商品登录路径
        //判断路径的后缀名 如果是js文件放行 jsp和js文件一字之差 contains无法判断
        String str = uri.substring(uri.lastIndexOf("."));
        if(str!=null){
            if(".js".equals(str)){
                filterChain.doFilter(servletRequest,servletResponse);
                return;
            }
        }
        if(uri.contains("/login")||uri.contains(".css")
                ||uri.contains(".jpg")||uri.contains(".png")
                ||uri.contains(".gif")||uri.contains(".eot")
                ||uri.contains(".png")){

        }

    }
    @Override
    public void destroy() {

    }
}
